package com.xy.biz.xd.domain.bo;

import com.xy.tool.context.UserContextHolder;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

/**
 *
 *
 * @author wwj
 * @date 2021-2-4
 */
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Data
public class DocumentFlowHandleBO {

	/**
	 * 文档流程处理Id
	 */
	private Long documentFlowHandleId;
	/**
	 * 文档流程Id
	 */
	private Long documentFlowId;
	/**
	 * 阶段：0-未定义
	 */
	private String phase;
	/**
	 * 结果：0-驳回，1-通过
	 */
	private Integer result;
	/**
	 * 处理意见
	 */
	private String opinion;
	/**
	 * 处理用户Id
	 */
	private Long handleUserId;
	/**
	 * 处理人部门Id
	 */
	private Long handleUserGroupId;
	/**
	 * 流程类型：0-未定义，1-新增流程，2-修订流程，3-作废流程，4-下载审批流程，5-借阅流程
	 */
	private Integer flowType;
	/**
	 * 文件编号
	 */
	private String documentCode;
	/**
	 * 租户Id，0表示不指定
	 */
	private Long tenantId;
	/**
	 * 创建用户Id
	 */
	private Long createUserId;
	/**
	 * 创建时间
	 */
	private LocalDateTime createTime;
	/**
	 * 更新时间
	 */
	private LocalDateTime updateTime;

//	public static DocumentFlowHandleBO build(DocumentFlowBO documentFlowBO,
//											 Long handleUserId,
//											 String phase,
//											 int result) {
//		return build(documentFlowBO, handleUserId, phase, result, documentFlowBO.getReason());
//	}
//
//	public static DocumentFlowHandleBO build(DocumentFlowBO documentFlowBO,
//											 Long handleUserId,
//											 String phase,
//											 int result,
//											 String opinion) {
//		return build(documentFlowBO, handleUserId, phase, result, opinion);
//	}

	public static DocumentFlowHandleBO build(DocumentFlowBO documentFlowBO,
											 Long handleUserId,
											 String phase,
											 int result,
											 String opinion) {
		DocumentFlowHandleBO documentFlowHandleBO = new DocumentFlowHandleBO();
		documentFlowHandleBO.setDocumentFlowId(documentFlowBO.getDocumentFlowId());
		documentFlowHandleBO.setPhase(phase);
		documentFlowHandleBO.setResult(result);
		documentFlowHandleBO.setOpinion(opinion);
		documentFlowHandleBO.setHandleUserId(handleUserId);
		documentFlowHandleBO.setHandleUserGroupId(UserContextHolder.getUserGroupId());
		documentFlowHandleBO.setFlowType(documentFlowBO.getFlowType());
		documentFlowHandleBO.setDocumentCode(documentFlowBO.getDocumentCode());
		documentFlowHandleBO.setTenantId(UserContextHolder.getTenantId());
		documentFlowHandleBO.setCreateUserId(UserContextHolder.getUserId());
		documentFlowHandleBO.setCreateTime(LocalDateTime.now());
		documentFlowHandleBO.setUpdateTime(LocalDateTime.now());
		documentFlowBO.addHandle(documentFlowHandleBO);
		return documentFlowHandleBO;
	}

}
